//
//  LoginViewController.m
//  Cheirapsis
//
//  Created by 于  冰 on 15/11/3.
//  Copyright © 2015年 mohe. All rights reserved.
//

#import "LoginViewController.h"
#import "RegisterViewController.h"
#import "ForgetViewController.h"
#import "MBProgressHUD.h"
#import "AVOSCloud.h"
#import "Define.h"
#import "BaseUtil.h"
#import "iToast.h"

@interface LoginViewController ()

@end

@implementation LoginViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.title =@"登录";
    self.view.backgroundColor =ALL233COROL;
    _code.secureTextEntry = YES;
    // Do any additional setup after loading the view from its nib.
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}
- (IBAction)login:(id)sender {
    if (!_account.text.length) {
        [[iToast makeText:@"用户名不能为空！"] show];
        return;
    }else if (![BaseUtil isMobileNumber:_account.text]) {
        [[iToast makeText:@"请输入手机号！"] show];
        return;
    }
    else if (!_code.text.length) {
        [[iToast makeText:@"密码不能为空！"] show];
        return;
    }
    // 登录
    [MBProgressHUD showHUDAddedTo:self.view animated:YES];
    [AVUser logInWithUsernameInBackground:_account.text password:_code.text block:^(AVUser *user, NSError *error) {
        [MBProgressHUD hideAllHUDsForView:self.view animated:YES];
        if (error) {
            [[iToast makeText:@"登陆失败"] show];
        }else{
            [[iToast makeText:@"登录成功"] show];
            [self.navigationController popViewControllerAnimated:YES];
            [[NSUserDefaults standardUserDefaults] setValue:_account.text forKey:@"userName"];
        }
    }];
    
}
- (IBAction)zhuCe:(id)sender {
    RegisterViewController *vc =[[RegisterViewController alloc]init];
    [self.navigationController pushViewController:vc animated:YES];
}
- (IBAction)zhaoHui:(id)sender {
    ForgetViewController *vc =[[ForgetViewController alloc]init];
    [self.navigationController pushViewController:vc animated:YES];

}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
